|
|
|
|
|
|
|
Solution 14
Registry Games, Part 4 |
|
|
|
|
|
|
|
|
So I'm lying out by the pool at the Disney World resort when this blimp flies overhead with the message, "Dan, call your publisher!" What a way to interrupt a vacation. . . . |
|
|
|
|
|
|
|
|
Okay, okay. Enough kidding around. You got me. The whole thing was intentional (or was it?). And if you haven't attempted to write the DisplayValue function yourself, I strongly encourage you to give it a try. |
|
|
|
|
|
|
|
|
Meanwhile, it's time to get serious. |
|
|
|
|
|
|
|
|
First, let's look at the VB declaration. The trick here is handling the lpData parameter. You've seen how to handle all the other situations in the preceding three puzzles. The lpData parameter is described in the documentation as follows: |
|
|
|
|
|
|
|
|
LPBYTE lpData, // address of data buffer |
|
|
|
|
|
|
|
|
The problem is that we have three different data types that can be loaded by this function: strings, Longs, and binary data. We also need to be able to pass a NULL value, since the first step will be to call the function with lpData set to NULL in order to obtain the data type and buffer size. |
|
|
|
|
|
|
|
|
Let's consider all the possible ways to handle each data type, as shown in Table S14-1. |
|
|
|
|
|
|
|
|
There are two general approaches you can take. You can choose the safest and easiest declaration for each data type and create multiple aliases for the RegQueryValueEx function. In this case, you would choose ByVal As Long for the null value, ByVal As String for string data, As Long for Long data, and As Byte for binary data. You can call the RegQueryValueEx function first with a NULL lpData value in order to determine the data type for the value, then call the appropriate alias for that data type. |
|
|
|
|
|
|
|
|
The other approach, which is shown in our solution, is to use the As Any data type and depend on the calling routine to pass the correct variable type in the lpData parameter. The RegQueryValueEx function will thus have the following declaration: |
|
|
|
|
|
|
|
|
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, lpData As Any, _
lpcbData As Long) As Long |
|
|
|
|
|